<%@ Page CodeBehind="Frame.aspx.cs" Language="c#" AutoEventWireup="false" Inherits="Sedna.javascript.Frame" %>
<%@ Import namespace="Sedna.Core.Globalization" %>
//<html xmlns="http://www.w3.org/1999/xhtml"><body><script>
Frame.inherit("Control");
Frame.prototype.frames = new Array();

function Frame(node){
    this.Control(node);
    
	this.eventManager=new EventManager();
	this.frame=document.getElementById(this.properties.getString("id"));
	this.header=document.getElementById(this.properties.getString("id")+"_header");
	this.bar=document.getElementById(this.properties.getString("id")+"_bar");
	this.image=document.getElementById(this.properties.getString("id")+"_image");
	this.title=document.getElementById(this.properties.getString("id")+"_title");
	this.stateControl=document.getElementById(this.properties.getString("stateControlId"));
	this.titleControl=document.getElementById(this.properties.getString("titleControlId"));
	this.onState=this.properties.getString("onState");
	this.offState=this.properties.getString("offState");
	this.frames.push(this);
	this.collapseOthers=false;
	this.setState(this.stateControl.value);
	this.collapseOthers=this.properties.getObject("collapseOthers");
	EventHandler.windowEventHandler.registerListener("load", this);	
}


Frame.prototype.onload=function () {
	/*
	var collapseOthers=this.collapseOthers;
	this.collapseOthers=false;
	this.setState(this.stateControl.value);
	this.collapseOthers=collapseOthers;
	*/
	this.updateHeaderText();
}


Frame.prototype.getContentState=function () { return ""; } //To be overloded in child classes

Frame.prototype.getHeaderText=function () {
	return this.title.firstChild.data;
}

Frame.prototype.setHeaderText=function (text) {
	this.title.firstChild.data=text;
}

Frame.prototype.setTitle=function (title) {
	this.titleControl.value=title;
	this.updateHeaderText();
}

Frame.prototype.getTitle=function () {
	return this.titleControl.value;
}

Frame.prototype.updateHeaderText=function () {
	if (this.stateControl.value!="Collapsed"){
		this.setHeaderText(this.titleControl.value);
		return;
	}
	this.setHeaderText(String.safeConcat(this.titleControl.value, this.getContentState(), " :: ")); 
}

Frame.prototype.collapse=function () {						
	this.stateControl.value="Collapsed";	

	this.frame.style.display="block";	
		
	this.bar.className="filtercollapsed";
	this.header.className="filter-off-state";
	this.header.style.display="block";
	this.image.src="<%= ImageManager.Relate(this, "ar2d.gif") %>";
	
	this.updateHeaderText();
}
						
Frame.prototype.hide=function () {
	this.stateControl.value="Hidden";
	
	this.frame.style.display="none";	
	/*	
	this.bar.className="filtercollapsed";
	this.header.style.display="none";
	*/
}

Frame.prototype.expand=function () {
	if (this.onBeforeExpand){
		this.onBeforeExpand();
	}
	
	this.stateControl.value="Expanded";

	this.frame.style.display="block";	

	this.bar.className="filter";
	this.header.className="filter-on-state";
	this.header.style.display="block";
	this.image.src="<%= ImageManager.Relate(this, "ar2u.gif") %>";
	
	if (this.collapseOthers){
		for (var i=0; i<this.frames.length; i++){
			if (this.frames[i]!=this){
				this.frames[i].setOffState();
			}
		}
	}
	
	this.updateHeaderText();
}



Frame.prototype.switchState=function () {
	if (this.stateControl.value=="Expanded") {
		this.setState(this.offState);
	} else {
		this.setState(this.onState);
	}
}

Frame.prototype.setState=function (state) {	
	this.eventManager.fireEvent("statechange", 
		{
			"target"		: this, 
			"currentState"	: this.getState(), 
			"newState"		: state
		}
	);
	switch (state){
		case ("Collapsed") : 
			this.collapse();
			break;
		case ("Expanded") :
			this.expand();
			break;
		case ("Hidden") :
			this.hide();
			break;
			
	}
} 

Frame.prototype.getState=function (){
	return this.stateControl.value;
}

Frame.prototype.setOnState=function () {
	this.setState(this.onState);	
}

Frame.prototype.setOffState=function () {
	this.setState(this.offState);
}	

Frame.prototype.setOffStateDelayed=function () {
	this.stateControl.value=this.offState;
}

Frame.prototype.setOnStateDelayed=function () {
	this.stateControl.value=this.onState;
}

//</script></body></html>
